package com.tuanzi.loan.log.service.impl;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.google.common.collect.Lists;
import com.tuanzi.loan.core.vo.PageSearcher;
import com.tuanzi.loan.log.entity.LoginLog;
import com.tuanzi.loan.log.entity.LoginLogAction;
import com.tuanzi.loan.log.repository.LoginLogRepository;
import com.tuanzi.loan.log.service.LoginLogService;
import com.tuanzi.loan.log.vo.request.LoginLogSearchRequest;
import com.tuanzi.loan.log.vo.response.LoginLogSearchResponse;

/**
 * @author Ray 2017/10/08
 */
@Service
@Transactional
public class LoginLogServiceImpl implements LoginLogService {

    @Autowired
    private LoginLogRepository loginLogRepository;

    @Async
    @Override
    public void log(LoginLogAction action, String username, String ip) {
        log(action, username, ip, null);
    }

    @Async
    @Override
    public void log(LoginLogAction action, String username, String ip, String remark) {
        LoginLog loginLog = new LoginLog();
        loginLog.setAction(action);
        loginLog.setActionTime(new Date());
        loginLog.setUsername(username);
        loginLog.setIp(ip);
        loginLog.setRemark(remark);
        loginLogRepository.save(loginLog);
    }

    @Override
    public Page<LoginLogSearchResponse> list(PageSearcher<LoginLogSearchRequest> pageSearcher) {
        return new PageImpl<LoginLogSearchResponse>(Lists.newArrayList());
    }
}
